package com.ruoyi.basic.controller.app;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.basic.domain.Column;
import com.ruoyi.basic.domain.Country;
import com.ruoyi.basic.domain.Language;
import com.ruoyi.basic.service.IColumnService;
import com.ruoyi.basic.service.ICountryService;
import com.ruoyi.basic.service.ILanguageService;

/**
 * App端基础模块Controller
 *
 * @author ruoyi
 * @date 2025-01-05
 */
@RestController
@RequestMapping("/app/basic")
public class BasicAppController extends BaseController
{
    @Autowired
    private IColumnService columnService;

    @Autowired
    private ICountryService countryService;

    @Autowired
    private ILanguageService languageService;

    /**
     * 获取所有栏目列表（影视类型）
     */
    @GetMapping("/columns")
    public AjaxResult getColumns()
    {
        Column query = new Column();
        query.setType("1"); // 1-内部栏目（影视类型）
        query.setStatus("0"); // 只返回正常状态
        List<Column> list = columnService.selectColumnList(query);
        return success(list);
    }



    /**
     * 获取栏目详情
     */
    @GetMapping("/column/{columnId}")
    public AjaxResult getColumn(@PathVariable Long columnId)
    {
        return success(columnService.selectColumnById(columnId));
    }

    /**
     * 根据栏目值获取栏目信息
     */
    @GetMapping("/column/value/{value}")
    public AjaxResult getColumnByValue(@PathVariable String value)
    {
        Column query = new Column();
        query.setValue(value);
        query.setStatus("0");
        List<Column> list = columnService.selectColumnList(query);
        if (list != null && !list.isEmpty()) {
            return success(list.get(0));
        }
        return error("栏目不存在");
    }

    /**
     * 获取所有国家列表
     */
    @GetMapping("/countries")
    public AjaxResult getCountries()
    {
        Country query = new Country();
        List<Country> list = countryService.selectCountryList(query);
        return success(list);
    }

    /**
     * 获取国家详情
     */
    @GetMapping("/country/{countryId}")
    public AjaxResult getCountry(@PathVariable Long countryId)
    {
        return success(countryService.selectCountryById(countryId));
    }

    /**
     * 获取所有语言列表
     */
    @GetMapping("/languages")
    public AjaxResult getLanguages()
    {
        Language query = new Language();
        List<Language> list = languageService.selectLanguageList(query);
        return success(list);
    }

    /**
     * 获取语言详情
     */
    @GetMapping("/language/{languageId}")
    public AjaxResult getLanguage(@PathVariable Long languageId)
    {
        return success(languageService.selectLanguageById(languageId));
    }
}
